<template>
  <!--大额身份列表-->
  <div class="statistics-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="8">
        <el-button type="primary" @click="add()">添加下月大额名额</el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="16">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyword"
              style="margin-right: 10px"
              placeholder="请输入身份证或手机号"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="queryForm.type"
              clearable
              placeholder="请选择"
              @change="selectType()"
            >
              <el-option
                v-for="item in type"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search">
              查询
            </el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh-right"
              @click="restart"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        sortable
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="mobile"
        label="手机号"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="name"
        label="姓名"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="identity"
        label="身份证"
      />
    </el-table>

    <!-- 弹窗 -->
    <el-dialog :title="wintit" :visible.sync="dialogFormVisible">
      <el-table
        v-loading="listLoading"
        :data="userlist"
        @selection-change="setSelectRows"
      >
        <el-table-column
          align="center"
          show-overflow-tooltip
          label="序号"
          sortable
          type="index"
        />
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="mobile"
          label="手机号"
        />
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="supplier_name"
          label="姓名"
        />
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="idcard"
          label="身份证"
        />
        <el-table-column align="center" label="操作">
          <template #default="{ row }">
            <el-button v-if="row.next_tax == 2" type="text" @click="send(row)">
              设置大额
            </el-button>
            <el-button
              v-if="row.next_tax == 1"
              type="warning"
              @click="send(row)"
            >
              取消大额
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page="queryForm.page"
        :page-size="queryForm.list_row"
        :layout="layout"
        :total="totalOnetag"
        @size-change="winSizeChange"
        @current-change="winCurrentChange"
      />
    </el-dialog>

    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
  import {
    getIdentityTaxSettingLists,
    getSupplierSearchLists,
    setIdentityTaxSettings,
  } from '@/api/common'

  export default {
    name: 'Identity',
    data() {
      return {
        type: [
          { value: 1, label: '本月' },
          { value: 2, label: '下个月' },
        ],
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
          type: 1,
        },
        form: {
          content: '',
        },
        disabled: false,
        listLoading: false,
        list: [],
        userlist: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        dialogFormVisible: false,
        wintit:'',
        totalOnetag:'',
      }
    },
    created() {
      this.getData()
    },
    methods: {
      handleDetail() {},
      //搜索
      search() {
        this.getData()
      },
      restart() {
        this.queryForm = []
        this.getData()
      },
      getData() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          search_input: this.queryForm.keyword,
          search_type: this.queryForm.type,
        }
        getIdentityTaxSettingLists(params).then((data) => {
          this.list = data.data
          this.total = data.count
        })
      },
      add() {
        this.dialogFormVisible = true
        this.wintit = '设置下个月大额'
        this.getUser()
      },
      getUser() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          type: 0,
        }
        getSupplierSearchLists(params).then((data) => {
          this.userlist = data.data
          this.totalOnetag = data.count
        })
      },
      send(row) {
        let params = {
          identity: row.idcard,
          name: row.supplier_name,
          mobile: row.mobile,
        }
        setIdentityTaxSettings(params).then((data) => {
          this.$message.success('修改成功！')
          this.getUser()
        })
      },
      setSelectRows() {},
      winSizeChange(val) {
        this.queryForm.list_row = val
        this.getUser()
      },
      winCurrentChange(val) {
        this.queryForm.page = val
        this.getUser()
      },
      handleSizeChange(val) {
        this.queryForm.list_row = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.getData()
      },
      selectType(e) {
        this.queryForm.types === e.value
      },
    },
  }
</script>

<style lang="scss" scoped>
  .el-button {
    font-size: 14px;
  }
</style>
